/**
 * Created by Administrator on 2017/12/12 0012.
 */
import React, {Component} from 'react'
export default class DTime extends Component {
  constructor(props) {
    super(props)
    this.state = {
      time: new Date()
    }
  }
  setTime() {
    this.setState({
      time: new Date()
    })
  }
  componentWillUnmount(){
    clearInterval(this.time)
  }
  componentDidMount() {
   this.time = setInterval(()=>{
     this.setTime()
   },1000)
  }
  render() {
    return (
      <div>
        <p>{this.state.time.toLocaleTimeString()}</p>
      </div>
    )
  }
}
